home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / comm / ftp4w24b.zip / vb / ftpproto.frm < prev    next >
Text File  |  1995-02-28  |  13KB  |  485 lines

  1. VERSION 2.00
  2. Begin Form FTP_form 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "FTP file transfer utility "
  6.    ClientHeight    =   4020
  7.    ClientLeft      =   1005
  8.    ClientTop       =   2385
  9.    ClientWidth     =   8085
  10.    Height          =   4710
  11.    Icon            =   FTPPROTO.FRX:0000
  12.    Left            =   945
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   4020
  16.    ScaleWidth      =   8085
  17.    Top             =   1755
  18.    Width           =   8205
  19.    Begin ListBox Dir_list 
  20.       Height          =   2955
  21.       Left            =   120
  22.       TabIndex        =   4
  23.       Top             =   480
  24.       Width           =   7815
  25.    End
  26.    Begin Line Line1 
  27.       X1              =   0
  28.       X2              =   8040
  29.       Y1              =   3480
  30.       Y2              =   3480
  31.    End
  32.    Begin Label Message 
  33.       DragMode        =   1  'Automatic
  34.       Height          =   255
  35.       Left            =   1320
  36.       TabIndex        =   1
  37.       Top             =   3600
  38.       Width           =   4815
  39.    End
  40.    Begin Label Label3 
  41.       BackColor       =   &H00C0C0C0&
  42.       Caption         =   "Messages :"
  43.       Height          =   255
  44.       Left            =   240
  45.       TabIndex        =   3
  46.       Top             =   3600
  47.       Width           =   1095
  48.    End
  49.    Begin Label Host_name 
  50.       BackColor       =   &H00C0C0C0&
  51.       Caption         =   "< Not connected >"
  52.       Height          =   255
  53.       Left            =   1680
  54.       TabIndex        =   2
  55.       Top             =   120
  56.       Width           =   1695
  57.    End
  58.    Begin Label Label1 
  59.       BackColor       =   &H00C0C0C0&
  60.       Caption         =   "Host :"
  61.       Height          =   255
  62.       Left            =   240
  63.       TabIndex        =   0
  64.       Top             =   120
  65.       Width           =   1215
  66.    End
  67.    Begin Menu Menu_connection 
  68.       Caption         =   "&Action"
  69.       Begin Menu Menu_connection_item 
  70.          Caption         =   "&Connect.."
  71.          Index           =   0
  72.       End
  73.       Begin Menu Menu_connection_item 
  74.          Caption         =   "&Disconnect.."
  75.          Index           =   1
  76.       End
  77.       Begin Menu Menu_connection_item 
  78.          Caption         =   "&Abort"
  79.          Index           =   2
  80.       End
  81.       Begin Menu Menu_connection_item 
  82.          Caption         =   "&Exit"
  83.          Index           =   3
  84.       End
  85.    End
  86.    Begin Menu Menu_file 
  87.       Caption         =   "&File"
  88.       Begin Menu Menu_file_item 
  89.          Caption         =   "&Get.."
  90.          Index           =   0
  91.       End
  92.       Begin Menu Menu_file_item 
  93.          Caption         =   "&Put.."
  94.          Index           =   1
  95.       End
  96.    End
  97.    Begin Menu Menu_directory 
  98.       Caption         =   "&Directory"
  99.       Begin Menu Menu_directory_item 
  100.          Caption         =   "&Change"
  101.          Index           =   0
  102.       End
  103.       Begin Menu Menu_directory_item 
  104.          Caption         =   "&Parent"
  105.          Index           =   1
  106.       End
  107.       Begin Menu Menu_directory_item 
  108.          Caption         =   "&Dir list"
  109.          Index           =   2
  110.       End
  111.    End
  112.    Begin Menu Menu_settings 
  113.       Caption         =   "&Settings"
  114.       Begin Menu Menu_setting_items 
  115.          Caption         =   "&Ascii type"
  116.          Index           =   0
  117.       End
  118.       Begin Menu Menu_setting_items 
  119.          Caption         =   "&Binary type"
  120.          Index           =   1
  121.       End
  122.       Begin Menu Menu_setting_items 
  123.          Caption         =   "&Mask"
  124.          Index           =   2
  125.       End
  126.    End
  127.    Begin Menu Quote_menu 
  128.       Caption         =   "&Quote"
  129.       Begin Menu Quote_command 
  130.          Caption         =   "&Command"
  131.       End
  132.    End
  133.    Begin Menu AboutMenu 
  134.       Caption         =   "A&bout"
  135.    End
  136. End
  137. Const MB_YESNO = 4, MB_ICONSTOP = 16, MB_DEFBUTTON2 = 256
  138. Const ID_YES = 6, ID_NO = 7
  139.  
  140. Sub AboutMenu_Click ()
  141.   '
  142.   Dim Msg, Endofl
  143.   Endofl = Chr$(13) & Chr$(10)
  144.   '
  145.   Msg = "   FTP File transfer utility" & Endofl
  146.   Msg = Msg & "   developed in Visual Basic" & Endofl
  147.   Msg = Msg & "      by Kees de Rooij and " & Endofl
  148.   Msg = Msg & "Richard Terpstra (terpstr2@ksla.nl)" & Endofl
  149.   Msg = Msg & " " & Endofl
  150.   Msg = Msg & "using FTP4W.DLL from Ph. Jounin (SNCF)" & Endofl
  151.   '
  152.   MsgBox Msg, 64, "About"
  153.   '
  154. End Sub
  155.  
  156. Sub Disable_menus ()
  157.   '
  158.   Menu_connection.Enabled = False
  159.   Menu_file.Enabled = False
  160.   Menu_directory.Enabled = False
  161.   Menu_settings.Enabled = False
  162.   Quote_menu.Enabled = False
  163.   '
  164. End Sub
  165.  
  166. Sub Do_display_options ()
  167.   '
  168.   Disable_menus
  169.   Ftp_form!Message.Caption = ""
  170.   Ftp_form.MousePointer = 11
  171.   '
  172. End Sub
  173.  
  174. Sub Enable_menus ()
  175.   '
  176.   Menu_connection.Enabled = True
  177.   Menu_file.Enabled = True
  178.   Menu_directory.Enabled = True
  179.   Menu_settings.Enabled = True
  180.   Quote_menu.Enabled = True
  181.   '
  182. End Sub
  183.  
  184. Function Exit_program () As Integer
  185.   'give a message box to enable the operator to terminate
  186.   'the program or not
  187.   '
  188.   Dim DgDef, Msg, Response, Title
  189.   '
  190.   Title = "Close application"
  191.   Msg = "The application is still connected " & Chr$(13) & Chr$(10)
  192.   Msg = Msg & "Do you want to finish anyway ?"
  193.   DgDef = MB_YESNO + MB_ICONSTOP + MB_DEFBUTTON2
  194.   Response = MsgBox(Msg, DgDef, Title)
  195.   '
  196.   Exit_program = Response
  197.   '
  198. End Function
  199.  
  200. Sub Form_Load ()
  201.   '
  202.   Connected = False
  203.   DirType = False
  204.   TransType = Asc(TYPE_A)
  205.   MaskType = "*.*"
  206.   '
  207.   Success = FtpInit(Hwnd)
  208.   If Success = FTPERR_OK Then
  209.     FtpSetSynchronousMode
  210.     Success = FtpSetType(TransType)
  211.   Else
  212.     Ms$ = FTP4W_Error(Success)
  213.     Ftp_form!Message.Caption = Ms$
  214.   End If
  215.   '
  216. End Sub
  217.  
  218. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  219.   '
  220.   'when finishing via - control program checks for connected
  221.   'and gives a message to the operator, he then can decide
  222.   'to finish or not
  223.   'Also a warning will be given when the release was not
  224.   'successfull
  225.   '
  226.   If Connected Then
  227.     If Exit_program() = ID_YES Then
  228.       Success = FtpLocalClose()  'do both Close
  229.       Success = FtpRelease()     'and Release
  230.       If Success <> FTPERR_OK Then
  231.         MsgBox "The application has not been Released succesfully", 64, "Information"
  232.         Cancel = False
  233.       End If
  234.       Cancel = False
  235.     Else
  236.       Cancel = True
  237.     End If
  238.   Else
  239.     Ftp_form!Message.Caption = ""
  240.     Success = FtpLocalClose()  'do both Close
  241.     Success = FtpRelease()     'and Release
  242.     If Success <> FTPERR_OK Then
  243.       MsgBox "The application has not been Released succesfully", 64, "Information"
  244.     End If
  245.     Cancel = False
  246.   End If
  247.   '
  248. End Sub
  249.  
  250. Sub Menu_connection_Click ()
  251.   'set menu active depending on connection
  252.   'connect
  253.   Menu_connection_item(0).Enabled = (Connected = False)
  254.   'disconnect
  255.   Menu_connection_item(1).Enabled = (Connected = True)
  256.   'abort
  257.   Menu_connection_item(2).Enabled = (Connected = True)
  258.   '
  259. End Sub
  260.  
  261. Sub Menu_connection_item_Click (Index As Integer)
  262.   'do action depending on item
  263.   '
  264.   Select Case Index
  265.   Case 0                    'Connect
  266.     ConnectForm.Show 1
  267.     If OKDialog = False Then
  268.       Exit Sub
  269.     End If
  270.     Do_display_options
  271.     Success = FtpLogin(HostName, Userid, Password, Hwnd, w%)
  272.     Undo_display_options
  273.     If Success = FTPERR_OK Then
  274.       Connected = True
  275.       Ftp_form.Host_name.Caption = HostName
  276.     Else
  277.       Ms$ = FTP4W_Error(Success)
  278.       Ftp_form!Message.Caption = Ms$
  279.     End If
  280.   Case 1                    'Disconnect
  281.     Do_display_options
  282.     Success = FtpCloseConnection()
  283.     Undo_display_options
  284.     If Success = FTPERR_OK Then
  285.       Connected = False
  286.       Ftp_form.Host_name.Caption = "< Not connected >"
  287.     Else
  288.       Ms$ = FTP4W_Error(Success)
  289.       Ftp_form!Message.Caption = Ms$
  290.     End If
  291.   Case 2                    'Abort
  292.     Do_display_options
  293.     Success = FtpAbort()
  294.     Undo_display_options
  295.     If Success <> FTPERR_OK Then
  296.       Ms$ = FTP4W_Error(Success)
  297.       Ftp_form!Message.Caption = Ms$
  298.     Else
  299.       Ftp_form!Message.Caption = "Abort OK"
  300.     End If
  301.   Case 3                    'Exit
  302.     If Connected Then       'when connected show tha dialog
  303.       If Exit_program() = ID_YES Then
  304.         Success = FtpLocalClose()  'do both Close
  305.         Success = FtpRelease()     'and Release
  306.         If Success <> FTPERR_OK Then
  307.           MsgBox "The Application has not been released succesfully", 64, "Info"
  308.         End If
  309.         End                      'exit program
  310.       End If
  311.     Else   'not connected
  312.       Success = FtpLocalClose()  'do both Close
  313.       Success = FtpRelease()     'and Release
  314.       If Success <> FTPERR_OK Then
  315.         MsgBox "The Application has not been released succesfully", 64, "Info"
  316.       End If
  317.       End                        'exit program
  318.     End If
  319.   End Select
  320.   '
  321. End Sub
  322.  
  323. Sub Menu_directory_Click ()
  324.   'set menu active depending on connection
  325.   'change
  326.   Menu_directory_item(0).Enabled = (Connected = True)
  327.   'parent
  328.   Menu_directory_item(1).Enabled = (Connected = True)
  329.   'dir list
  330.   Menu_directory_item(2).Enabled = (Connected = True)
  331.   '
  332. End Sub
  333.  
  334. Sub Menu_directory_item_Click (Index As Integer)
  335.   '
  336.   Dim C_dir$
  337.   '
  338.   Select Case Index
  339.   Case 0          'change
  340.     C_dir$ = InputBox$("Enter directory name : ", "Change directory")
  341.     Do_display_options
  342.     Success = FtpCWD(C_dir$)
  343.     Undo_display_options
  344.     If Success <> FTPERR_OK Then
  345.       Ms$ = FTP4W_Error(Success)
  346.       Ftp_form!Message.Caption = Ms$
  347.     Else
  348.       Ftp_form!Message.Caption = "Change dir OK"
  349.     End If
  350.   Case 1          'parent
  351.     C_dir$ = ".."
  352.     Do_display_options
  353.     Success = FtpCWD(C_dir$)
  354.     Undo_display_options
  355.     If Success <> FTPERR_OK Then
  356.       Ms$ = FTP4W_Error(Success)
  357.       Ftp_form!Message.Caption = Ms$
  358.     Else
  359.       Ftp_form!Message.Caption = "Change dir OK"
  360.     End If
  361.   Case 2
  362.     DirType = False
  363.     Do_display_options
  364.     Do_the_dirlist
  365.     Ftp_form.MousePointer = 0
  366.     Enable_menus
  367.   End Select
  368.   '
  369. End Sub
  370.  
  371. Sub Menu_file_Click ()
  372.   'set menu active depending on connection
  373.   'put
  374.   Menu_file_item(0).Enabled = (Connected = True)
  375.   'get
  376.   Menu_file_item(1).Enabled = (Connected = True)
  377.   '
  378. End Sub
  379.  
  380. Sub Menu_file_item_Click (Index As Integer)
  381.   '
  382.   Select Case Index
  383.   Case 0      'get
  384.     Get_file.Show 1
  385.     If OKDialog = False Then Exit Sub
  386.     '
  387.     Do_display_options
  388.     Success = FtpRecvFile(Src_nam, Dest_nam, TransType, BNotify%, Hwnd, Msg%)
  389.     Undo_display_options
  390.     If Success <> FTPERR_OK Then
  391.       Ms$ = FTP4W_Error(Success)
  392.       Ftp_form!Message.Caption = Ms$
  393.     Else
  394.       Ftp_form!Message.Caption = "Receive file OK"
  395.     End If
  396.   Case 1      'put
  397.     Put_file.Show 1
  398.     If OKDialog = False Then Exit Sub
  399.     Do_display_options
  400.     Success = FtpSendFile(Src_nam, Dest_nam, TransType, BNotify%, Hwnd, Msg%)
  401.     Undo_display_options
  402.     If Success <> FTPERR_OK Then
  403.       Ms$ = FTP4W_Error(Success)
  404.       Ftp_form!Message.Caption = Ms$
  405.     Else
  406.       Ftp_form!Message.Caption = "Send file OK"
  407.     End If
  408.   End Select
  409.   '
  410. End Sub
  411.  
  412. Sub Menu_setting_items_Click (Index As Integer)
  413.   '
  414.   Select Case Index
  415.   Case 0                     'Ascii
  416.     TransType = Asc(TYPE_A)
  417.   Case 1                     'binary
  418.     TransType = Asc(TYPE_I)
  419.   Case 2                     'mask
  420.     MaskType = Get_mask_type()
  421.     Do_display_options
  422.     Do_the_dirlist
  423.     Ftp_form.MousePointer = 0
  424.     Enable_menus
  425.   End Select
  426.   '
  427. End Sub
  428.  
  429. Sub Menu_settings_Click ()
  430.   '
  431.   Menu_setting_items(0).Checked = (TransType = Asc(TYPE_A))
  432.   Menu_setting_items(1).Checked = (TransType = Asc(TYPE_I))
  433.   '
  434.   Menu_setting_items(0).Enabled = (Connected = True)
  435.   Menu_setting_items(1).Enabled = (Connected = True)
  436.   Menu_setting_items(2).Enabled = (Connected = True)
  437.   '
  438. End Sub
  439.  
  440. Sub Quote_command_Click ()
  441.   'execute a command not implemented as standard command
  442.   'in FTP4W.BAS
  443.   '
  444.   Dim Answ$, DefVal, Msg, Title
  445.   Dim Result As String
  446.   '
  447.   Result = String$(255, 32)     'init the string ! essential
  448.   '
  449.   DefVal = ""
  450.   Msg = "Enter FTP command : "
  451.   Title = "Quote option for FTP"
  452.   '
  453.   Answ$ = InputBox$(Msg, Title, DefVal)
  454.   If Len(Trim$(Answ$)) = 0 Then
  455.     Exit Sub
  456.   Else
  457.     Do_display_options
  458.     Success = FtpQuote(Answ$, Result, Len(Result))
  459.     Undo_display_options
  460.     If Success = FTPERR_OK Then
  461.       Result = Trim$(Result)
  462.       Result = Left$(Result, Len(Result) - 1)
  463.       Ftp_form!Message.Caption = "FTP Quote OK" 'Result
  464.     Else
  465.       M$ = FTP4W_Error(Success)
  466.       Ftp_form!Message.Caption = M$
  467.     End If
  468.   End If
  469.   '
  470. End Sub
  471.  
  472. Sub Quote_menu_Click ()
  473.   '
  474.   Quote_command.Enabled = (Connected = True)
  475.   '
  476. End Sub
  477.  
  478. Sub Undo_display_options ()
  479.   '
  480.   Ftp_form.MousePointer = 0
  481.   Enable_menus
  482.   '
  483. End Sub
  484.  
  485.